// 工具函数
export function getDataType(values: any) {
    // 获取数据真实类型
    return Object
        .prototype
        .toString
        .call(values)
        .replace(/\[(\S+) (\S+)\]/, '$2')
}

export function base64ToFile(base64Data, filename) {
    // 将base64的数据部分提取出来
    const parts = base64Data.split(';base64,');
    const contentType = parts[0].split(':')[1];
    const raw = window.atob(parts[1]);
    const rawLength = raw.length;
    const uInt8Array = new Uint8Array(rawLength);

    for (let i = 0; i < rawLength; ++i) {
        uInt8Array[i] = raw.charCodeAt(i);
    }

    // 使用Blob和File构造函数创建File对象
    const blob = new Blob([uInt8Array], {type: contentType});
    const file = new File([blob], filename, {type: contentType});
    return file;
}

export const tagTypes = [
    "#FFA2D3", "success", "#1ac0c6", "warning", "magenta", "#263dc4", "purple", "volcano", "orange", "cyan"
];

export function randomNumber(min = 0, max = 9) {
    // 生成范围数值
    return Math.floor(Math.random() * (max - min + 1)) + min;
}
